package com.demo.controller;

import com.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.fisco.bcos.sdk.BcosSDK;
import org.fisco.bcos.sdk.client.Client;
import org.fisco.bcos.sdk.client.protocol.response.BcosTransactionReceipt;
import org.fisco.bcos.sdk.crypto.hash.Hash;
import org.fisco.bcos.sdk.model.TransactionReceipt;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

@RestController
@Slf4j
public class Select {
    // 获取配置文件路径
    public final String configFile = Select.class.getClassLoader().getResource("config-example.toml").getPath();
        @GetMapping("/select")
    public Result<String> select(String Hash){
            log.info("Hash:"+Hash);
        // 初始化BcosSDK
        BcosSDK sdk =  BcosSDK.build(configFile);
        // 为群组1初始化client
        Client client = sdk.getClient(Integer.valueOf(1));
        BcosTransactionReceipt transactionReceipt = client.getTransactionReceipt(Hash);
        return   Result.sucess(transactionReceipt.getTransactionReceipt().get().toString()) ;
    }
}
